﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:clr="clr-namespace:System;assembly=mscorlib" xmlns:clr2="clr-namespace:System.Collections;assembly=mscorlib" xmlns:local="clr-namespace:WPG" xmlns:data="clr-namespace:WPG.Data" xmlns:converters="clr-namespace:WPG.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

	<!-- WPG CheckBoxFocusVisual Style -->
	<Style x:Key="CheckBoxFocusVisual">
		<Setter Property="Control.Template">
			<Setter.Value>
				<ControlTemplate>
					<Border>
						<Rectangle Margin="15,0,0,0" Stroke="#60000000" StrokeThickness="1" StrokeDashArray="1 2" />
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<!-- WPG CheckBox Style -->
	<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=CheckBoxStyle}" TargetType="{x:Type CheckBox}">
		<Setter Property="SnapsToDevicePixels" Value="true" />
		<Setter Property="FocusVisualStyle" Value="{StaticResource CheckBoxFocusVisual}" />
		<Setter Property="Background" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=WindowBackgroundBrush}}" />
		<Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=NormalBorderBrush}}" />
		<Setter Property="BorderThickness" Value="1" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type CheckBox}">

					<!-- BulletDecorator is used to provide baseline alignment between the checkmark and the Content -->
					<BulletDecorator Background="Transparent">
						<BulletDecorator.Bullet>
							<Grid Width="13" Height="13">
								<Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" />
                                <Path x:Name="CheckMark" Stroke="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=GlyphBrush}}" StrokeThickness="2" SnapsToDevicePixels="False" Data="M 2 2 L 11 11 M 2 11 L 11 2" />
							</Grid>
						</BulletDecorator.Bullet>
						<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True" />
					</BulletDecorator>

					<!-- This uses Visibility to hide and show the CheckMark on IsChecked -->
					<ControlTemplate.Triggers>
						<Trigger Property="IsChecked" Value="false">
							<Setter Property="Visibility" Value="Collapsed" TargetName="CheckMark" />
						</Trigger>

						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Background" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=DisabledBackgroundBrush}}" TargetName="Border" />
							<Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=DisabledBorderBrush}}" TargetName="Border" />
						</Trigger>
					</ControlTemplate.Triggers>

				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

</ResourceDictionary>